%Read the HYB and ETT data from 1980 tp present
%Compare the dat against ABG and TIR 
% First ETT and TIR for ABG go to line numeber 120
pp=1;
for i = 1980:2002,
fid = fopen(['C:\Manoj\geomag\wdc\ett\HDZ\' sprintf('ETT%4d',i) 'H.WDC'],'rt');
disp(['C:\Manoj\geomag\wdc\ett\HDZ\' sprintf('%4d',i) 'h.WDC']);
if fid ~= -1,
[data,data1] = wdc_read(fid,'H');
h_ett(pp:pp+size(data,1)*24-1) = reshape(data',[1,size(data,1)*24]);
pp=pp+size(data,1)*24;
end;
end;

pp =1 ;
for yr = 1980:2002,
    for mnth = 1:12,
        dayys = daysinmonth(yr,mnth);
        for dai = 1:dayys,
            ett_fday(pp:pp+24-1) = datenum(yr,mnth,dai,0:23,30,0);
            pp = pp +24;
        end;
    end;
end;
% plot(ett_fday,h_ett);
% 
% fid = fopen('c:\manoj\geomag\data\TRD\tRD8089.wdc','rt');
% [data,data1,fday1] = wdc_read(fid);
% [trash,l] = intersect(fday1(1):fday1(end),fday1);
% TRD8089 = ones([length(fday1(1):fday1(end)),24])*NaN;
% TRD8089(l,:) = data;
%missing TRD ! 31 oct 1981, 31 dec 1980 for H

% fid = fopen('c:\manoj\geomag\data\TRD\tRD9099.wdc','rt');
% [data,data1,fday2] = wdc_read(fid);
% TRD9099 = data;
% TRD = [TRD8089;TRD9099];
% h_trd = reshape(TRD',[1,length(TRD)*24]);
% 
% %Z Trivandrum
% fid = fopen('c:\manoj\geomag\data\TRD\tRD8089.wdc','rt');
% [data,data1,fday1] = wdc_read(fid);
% [trash,l] = intersect(fday1(1):fday1(end),fday1);
% TRD8089Z = ones([length(fday1(1):fday1(end)),24])*NaN;
% TRD8089Z(l,:) = data;
% 
% fid = fopen('c:\manoj\geomag\data\TRD\tRD9099.wdc','rt');
% [data,data1,fday2] = wdc_read(fid);
% [trash,l] = intersect(fday2(1):fday2(end),fday2);
% TRD9099Z = ones([length(fday2(1):fday2(end)),24])*NaN;
% TRD9099Z(l,:) = data;
% 
% TRDZ = [TRD8089Z;TRD9099Z];
% z_trd = reshape(TRDZ',[1,length(TRDZ)*24]);
% 
%Z Ett
pp=1;
for i = 1980:2002,
fid = fopen(['C:\Manoj\geomag\wdc\ett\HDZ\' sprintf('ETT%4d',i) 'Z.WDC'],'rt');
disp(['C:\Manoj\geomag\wdc\ett\HDZ\' sprintf('%4d',i) 'Z.WDC']);
if fid ~= -1,
[data,data1] = wdc_read(fid,'Z');
z_ett(pp:pp+size(data,1)*24-1) = reshape(data',[1,size(data,1)*24]);
pp=pp+size(data,1)*24;
end;
end;

pp=1;
for i = 1980:2002,
fid = fopen(['C:\Manoj\geomag\wdc\ett\HDZ\' sprintf('ETT%4d',i) 'D.WDC'],'rt');
disp(['C:\Manoj\geomag\wdc\ett\HDZ\' sprintf('%4d',i) 'D.WDC']);
if fid ~= -1,
[data,data1] = wdc_read(fid,'D');
d_ett(pp:pp+size(data,1)*24-1) = reshape(data',[1,size(data,1)*24]);
pp=pp+size(data,1)*24;
end;
end;

%D Declination

% pp=1;
% for i = 0:19,
% fid = fopen(['c:\manoj\geomag\wdc\ett' sprintf('%2d',i+80) 'D.WDC'],'rt');
% if fid ~= -1,
% [data,data1] = wdc_read(fid);
% d_ett(pp:pp+size(data,1)*24-1) = reshape(data',[1,size(data,1)*24]);
% 
% pp=pp+size(data,1)*24;
% end;
% end;
% 
% pp =1 ;
% for yr = 1980:1999,
%     for mnth = 1:12,
%         dayys = daysinmonth(yr,mnth);
%         for dai = 1:dayys,
%             ett_fday(pp:pp+24-1) = datenum(yr,mnth,dai,0:23,30,0);
%             pp = pp +24;
%         end;
%     end;
% end;
% 
% %Z Trivandrum
% fid = fopen('c:\manoj\geomag\data\TRD\tRD8089.wdc','rt');
% [data,data1,fday1] = wdc_read(fid);
% [trash,l] = intersect(fday1(1):fday1(end),fday1);
% TRD8089D = ones([length(fday1(1):fday1(end)),24])*NaN;
% TRD8089D(l,:) = data;
% 
% fid = fopen('c:\manoj\geomag\data\TRD\tRD9099.wdc','rt');
% [data,data1,fday2] = wdc_read(fid);
% [trash,l] = intersect(fday2(1):fday2(end),fday2);
% TRD9099D = ones([length(fday2(1):fday2(end)),24])*NaN;
% TRD9099D(l,:) = data;
% 
% TRDD = [TRD8089D;TRD9099D];
% d_trd = reshape(TRDD',[1,length(TRDD)*24]);

%ABG and HYB
%H
pp=1;
for i = 1983:2004,
fid = fopen(['C:\Manoj\geomag\wdc\hyb\HDZ\' sprintf('HYB%4d',i) 'H.WDC'],'rt');
disp(['C:\Manoj\geomag\wdc\ett\HDZ\' sprintf('%4d',i) 'H.WDC']);
if fid ~= -1,
[data,data1] = wdc_read(fid,'H');
h_hyb(pp:pp+size(data,1)*24-1) = reshape(data',[1,size(data,1)*24]);
pp=pp+size(data,1)*24;
end;
end;

pp =1 ;
for yr = 1983:2004,
    for mnth = 1:12,
        dayys = daysinmonth(yr,mnth);
        for dai = 1:dayys,
            hyb_fday(pp:pp+24-1) = datenum(yr,mnth,dai,0:23,30,0);
            pp = pp +24;
        end;
    end;
end;
% plot(hyb_fday,h_hyb);
% 
% 
% fid = fopen('c:\manoj\geomag\wdc\abg\abg8089.dat','rt');
% [data,data1,fday1] = wdc_read(fid);
% [trash,l] = intersect(fday1(1):fday1(end),fday1);
% ABG8089 = ones([length(fday1(1):fday1(end)),24])*NaN;
% ABG8089(l,:) = data;
% %missing TRD ! 31 oct 1981, 31 dec 1980 for H
% 
% 
% fid = fopen('c:\manoj\geomag\wdc\abg\abg9099.dat','rt');
% [data,data1,fday2] = wdc_read(fid);
% ABG9099 = data;
% ABG = [ABG8089;ABG9099];
% h_abg = reshape(ABG',[1,length(ABG)*24]);

%Z 
pp=1;
for i = 1983:2004,
fid = fopen(['C:\Manoj\geomag\wdc\hyb\HDZ\' sprintf('HYB%4d',i) 'Z.WDC'],'rt');
disp(['C:\Manoj\geomag\wdc\ett\HDZ\' sprintf('%4d',i) 'Z.WDC']);
if fid ~= -1,
[data,data1] = wdc_read(fid,'Z');
z_hyb(pp:pp+size(data,1)*24-1) = reshape(data',[1,size(data,1)*24]);
pp=pp+size(data,1)*24;
end;
end;

% 
% fid = fopen('c:\manoj\geomag\wdc\abg\abg8089.dat','rt');
% [data,data1,fday1] = wdc_read(fid);
% [trash,l] = intersect(fday1(1):fday1(end),fday1);
% ABG8089 = ones([length(fday1(1):fday1(end)),24])*NaN;
% ABG8089(l,:) = data;
% %missing TRD ! 31 oct 1981, 31 dec 1980 for H
% 
% 
% fid = fopen('c:\manoj\geomag\wdc\abg\abg9099.dat','rt');
% [data,data1,fday2] = wdc_read(fid);
% ABG9099 = data;
% ABG = [ABG8089;ABG9099];
% z_abg = reshape(ABG',[1,length(ABG)*24]);

%D Declination

pp=1;
for i = 1983:2004,
fid = fopen(['C:\Manoj\geomag\wdc\hyb\HDZ\' sprintf('HYB%4d',i) 'D.WDC'],'rt');
disp(['C:\Manoj\geomag\wdc\ett\HDZ\' sprintf('%4d',i) 'D.WDC']);
if fid ~= -1,
[data,data1] = wdc_read(fid,'D');
d_hyb(pp:pp+size(data,1)*24-1) = reshape(data',[1,size(data,1)*24]);
pp=pp+size(data,1)*24;
end;
end;


% pp =1 ;
% for yr = 1980:1999,
%     for mnth = 1:12,
%         dayys = daysinmonth(yr,mnth);
%         for dai = 1:dayys,
%             ett_fday(pp:pp+24-1) = datenum(yr,mnth,dai,0:23,30,0);
%             pp = pp +24;
%         end;
%     end;
% end;
% 
% fid = fopen('c:\manoj\geomag\wdc\abg\abg8089.dat','rt');
% [data,data1,fday1] = wdc_read(fid);
% [trash,l] = intersect(fday1(1):fday1(end),fday1);
% ABG8089 = ones([length(fday1(1):fday1(end)),24])*NaN;
% ABG8089(l,:) = data;
% 
% 
% fid = fopen('c:\manoj\geomag\wdc\abg\abg9099.dat','rt');
% [data,data1,fday2] = wdc_read(fid);
% ABG9099 = data;
% ABG = [ABG8089;ABG9099];
% d_abg = reshape(ABG',[1,length(ABG)*24]);
% 
% % Comparison of ETT and KOD data from 2000-2002
% 
% pp =1 ;
% for yr = 1980:2002,
%     for mnth = 1:12,
%         dayys = daysinmonth(yr,mnth);
%         for dai = 1:dayys,
%             ett_fday(pp:pp+24-1) = datenum(yr,mnth,dai,0:23,30,0);
%             pp = pp +24;
%         end;
%     end;
% end;
% 
% fid = fopen('c:\manoj\geomag\wdc\ett\ett0002.wdc','rt');
% [data,data1,fday1] = wdc_read(fid);
% [trash,l] = intersect(fday1(1):fday1(end),fday1);
% ETT0002 = ones([length(fday1(1):fday1(end)),24])*NaN;
% ETT0002(l,:) = data;
% h_ett1 = reshape(ETT0002',[1,length(ETT0002)*24]);